/******************************************************************************
 *
 * package:
 * file:        dailyfileappender.h
 * created:     Jaenner 2015
 * author:      Johann Anhofer
 *
 *
 * Copyright 2015 Johann Anhofer
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 ******************************************************************************/

#ifndef LOG4QT_DAILYFILEAPPENDER_H
#define LOG4QT_DAILYFILEAPPENDER_H

#include "fileappender.h"

#include <QString>
#include <QDate>

namespace Log4Qt
{

/*!
 * \brief The class DailyFileAppender extends FileAppender so that the
 * a log file is created for each day
 */
class  LOG4QT_EXPORT DailyFileAppender : public FileAppender
{
    Q_OBJECT

    //! The property holds the date pattern used by the appender.
    Q_PROPERTY(QString datePattern READ datePattern WRITE setDatePattern)
public:
    explicit DailyFileAppender(QObject *parent = nullptr);
    DailyFileAppender(const LayoutSharedPtr &layout, const QString &fileName, const QString &datePattern = QString(), QObject *parent = nullptr);

    QString datePattern() const;
    void setDatePattern(const QString &datePattern);

    void activateOptions() override;

    void setLogFileForCurrentDay();

    void append(const LoggingEvent &event) override;

private:
    Q_DISABLE_COPY(DailyFileAppender)
    void rollOver();
    QString appendDateToFilename() const;

    QString mDatePattern;
    QDate mLastDate;
    QString mOriginalFilename;
};

}

#endif // LOG4QT_DAILYFILEAPPENDER_H
